
extern "C" {
    pub type options;
    fn free(_: *mut ());
    fn strcmp(_: *const i8, _: *const i8) -> i32;
    fn time(__timer: *mut time_t) -> time_t;
    fn strlcpy(_: *mut i8, _: *const i8, _: size_t) -> size_t;
    fn xmalloc(_: size_t) -> *mut ();
    fn xreallocarray(_: *mut (), _: size_t, _: size_t) -> *mut ();
    fn xstrdup(_: *const i8) -> *mut i8;
    fn xasprintf(_: *mut *mut i8, _: *const i8, _: ...) -> i32;
    static mut global_options: *mut options;
    fn notify_paste_buffer(_: *const i8, _: i32);
    fn options_get_number(_: *mut options, _: *const i8) -> i64;
    fn utf8_strvis(_: *mut i8, _: *const i8, _: size_t, _: i32) -> i32;
}
pub type __u_int = u32;
pub type __time_t = i64;
pub type u_int = __u_int;
pub type time_t = __time_t;
pub type size_t = u64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct paste_buffer {
    pub data: *mut i8,
    pub size: size_t,
    pub name: *mut i8,
    pub created: time_t,
    pub automatic: i32,
    pub order: u_int,
    pub name_entry: C2RustUnnamed_0,
    pub time_entry: C2RustUnnamed,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed {
    pub rbe_left: *mut paste_buffer,
    pub rbe_right: *mut paste_buffer,
    pub rbe_parent: *mut paste_buffer,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_0 {
    pub rbe_left: *mut paste_buffer,
    pub rbe_right: *mut paste_buffer,
    pub rbe_parent: *mut paste_buffer,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct paste_time_tree {
    pub rbh_root: *mut paste_buffer,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct paste_name_tree {
    pub rbh_root: *mut paste_buffer,
}
static mut paste_next_index: u_int = 0;
static mut paste_next_order: u_int = 0;
static mut paste_num_automatic: u_int = 0;
static mut paste_by_name: paste_name_tree = paste_name_tree {
    rbh_root: 0 as *const paste_buffer as *mut paste_buffer,
};
static mut paste_by_time: paste_time_tree = paste_time_tree {
    rbh_root: 0 as *const paste_buffer as *mut paste_buffer,
};
extern "C" fn paste_name_tree_RB_FIND(
    mut head: *mut paste_name_tree,
    mut elm: *mut paste_buffer,
) -> *mut paste_buffer {
    let mut tmp: *mut paste_buffer = unsafe { (*head).rbh_root };
    let mut comp: i32 = 0;
    while !tmp.is_null() {
        comp = paste_cmp_names(elm, tmp);
        if comp < 0 {
            tmp = unsafe { (*tmp).name_entry.rbe_left };
        } else if comp > 0 {
            tmp = unsafe { (*tmp).name_entry.rbe_right };
        } else {
            return tmp;
        }
    }
    return std::ptr::null_mut::<paste_buffer>();
}
extern "C" fn paste_name_tree_RB_INSERT_COLOR(
    mut head: *mut paste_name_tree,
    mut elm: *mut paste_buffer,
) {
    let mut parent: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut gparent: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut tmp: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    loop {
        parent = unsafe { (*elm).name_entry.rbe_parent };
        if parent.is_null() || (unsafe { (*parent).name_entry.rbe_color }) != 1 {
            break;
        }
        gparent = unsafe { (*parent).name_entry.rbe_parent };
        if parent == (unsafe { (*gparent).name_entry.rbe_left }) {
            tmp = unsafe { (*gparent).name_entry.rbe_right };
            if !tmp.is_null() && (unsafe { (*tmp).name_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).name_entry.rbe_color = 0 });
                (unsafe { (*parent).name_entry.rbe_color = 0 });
                (unsafe { (*gparent).name_entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).name_entry.rbe_right }) == elm {
                    tmp = unsafe { (*parent).name_entry.rbe_right };
                    (unsafe { (*parent).name_entry.rbe_right = (*tmp).name_entry.rbe_left });
                    if !(unsafe { (*parent).name_entry.rbe_right }).is_null() {
                        (unsafe { (*(*tmp).name_entry.rbe_left).name_entry.rbe_parent = parent });
                    }
                    (unsafe { (*tmp).name_entry.rbe_parent = (*parent).name_entry.rbe_parent });
                    if !(unsafe { (*tmp).name_entry.rbe_parent }).is_null() {
                        if parent
                            == (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_left })
                        {
                            (unsafe {
                                (*(*parent).name_entry.rbe_parent).name_entry.rbe_left = tmp
                            });
                        } else {
                            (unsafe {
                                (*(*parent).name_entry.rbe_parent).name_entry.rbe_right = tmp
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).name_entry.rbe_left = parent });
                    (unsafe { (*parent).name_entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).name_entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).name_entry.rbe_color = 0 });
                (unsafe { (*gparent).name_entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).name_entry.rbe_left };
                (unsafe { (*gparent).name_entry.rbe_left = (*tmp).name_entry.rbe_right });
                if !(unsafe { (*gparent).name_entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).name_entry.rbe_right).name_entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).name_entry.rbe_parent = (*gparent).name_entry.rbe_parent });
                if !(unsafe { (*tmp).name_entry.rbe_parent }).is_null() {
                    if gparent
                        == (unsafe { (*(*gparent).name_entry.rbe_parent).name_entry.rbe_left })
                    {
                        (unsafe { (*(*gparent).name_entry.rbe_parent).name_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*gparent).name_entry.rbe_parent).name_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).name_entry.rbe_right = gparent });
                (unsafe { (*gparent).name_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).name_entry.rbe_parent }).is_null();
            }
        } else {
            tmp = unsafe { (*gparent).name_entry.rbe_left };
            if !tmp.is_null() && (unsafe { (*tmp).name_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).name_entry.rbe_color = 0 });
                (unsafe { (*parent).name_entry.rbe_color = 0 });
                (unsafe { (*gparent).name_entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).name_entry.rbe_left }) == elm {
                    tmp = unsafe { (*parent).name_entry.rbe_left };
                    (unsafe { (*parent).name_entry.rbe_left = (*tmp).name_entry.rbe_right });
                    if !(unsafe { (*parent).name_entry.rbe_left }).is_null() {
                        (unsafe { (*(*tmp).name_entry.rbe_right).name_entry.rbe_parent = parent });
                    }
                    (unsafe { (*tmp).name_entry.rbe_parent = (*parent).name_entry.rbe_parent });
                    if !(unsafe { (*tmp).name_entry.rbe_parent }).is_null() {
                        if parent
                            == (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_left })
                        {
                            (unsafe {
                                (*(*parent).name_entry.rbe_parent).name_entry.rbe_left = tmp
                            });
                        } else {
                            (unsafe {
                                (*(*parent).name_entry.rbe_parent).name_entry.rbe_right = tmp
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).name_entry.rbe_right = parent });
                    (unsafe { (*parent).name_entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).name_entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).name_entry.rbe_color = 0 });
                (unsafe { (*gparent).name_entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).name_entry.rbe_right };
                (unsafe { (*gparent).name_entry.rbe_right = (*tmp).name_entry.rbe_left });
                if !(unsafe { (*gparent).name_entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).name_entry.rbe_left).name_entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).name_entry.rbe_parent = (*gparent).name_entry.rbe_parent });
                if !(unsafe { (*tmp).name_entry.rbe_parent }).is_null() {
                    if gparent
                        == (unsafe { (*(*gparent).name_entry.rbe_parent).name_entry.rbe_left })
                    {
                        (unsafe { (*(*gparent).name_entry.rbe_parent).name_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*gparent).name_entry.rbe_parent).name_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).name_entry.rbe_left = gparent });
                (unsafe { (*gparent).name_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).name_entry.rbe_parent }).is_null();
            }
        }
    }
    (unsafe { (*(*head).rbh_root).name_entry.rbe_color = 0 });
}
extern "C" fn paste_name_tree_RB_INSERT(
    mut head: *mut paste_name_tree,
    mut elm: *mut paste_buffer,
) -> *mut paste_buffer {
    let mut tmp: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut parent: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut comp: i32 = 0;
    tmp = unsafe { (*head).rbh_root };
    while !tmp.is_null() {
        parent = tmp;
        comp = paste_cmp_names(elm, parent);
        if comp < 0 {
            tmp = unsafe { (*tmp).name_entry.rbe_left };
        } else if comp > 0 {
            tmp = unsafe { (*tmp).name_entry.rbe_right };
        } else {
            return tmp;
        }
    }
    (unsafe { (*elm).name_entry.rbe_parent = parent });
    (unsafe { (*elm).name_entry.rbe_right = std::ptr::null_mut::<paste_buffer>() });
    (unsafe { (*elm).name_entry.rbe_left = (*elm).name_entry.rbe_right });
    (unsafe { (*elm).name_entry.rbe_color = 1 });
    if !parent.is_null() {
        if comp < 0 {
            (unsafe { (*parent).name_entry.rbe_left = elm });
        } else {
            (unsafe { (*parent).name_entry.rbe_right = elm });
        }
    } else {
        (unsafe { (*head).rbh_root = elm });
    }
    paste_name_tree_RB_INSERT_COLOR(head, elm);
    return std::ptr::null_mut::<paste_buffer>();
}
extern "C" fn paste_name_tree_RB_REMOVE(
    mut head: *mut paste_name_tree,
    mut elm: *mut paste_buffer,
) -> *mut paste_buffer {
    let mut current_block: u64;
    let mut child: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut parent: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut old: *mut paste_buffer = elm;
    let mut color: i32 = 0;
    if (unsafe { (*elm).name_entry.rbe_left }).is_null() {
        child = unsafe { (*elm).name_entry.rbe_right };
        current_block = 7245201122033322888;
    } else if (unsafe { (*elm).name_entry.rbe_right }).is_null() {
        child = unsafe { (*elm).name_entry.rbe_left };
        current_block = 7245201122033322888;
    } else {
        let mut left: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
        elm = unsafe { (*elm).name_entry.rbe_right };
        loop {
            left = unsafe { (*elm).name_entry.rbe_left };
            if left.is_null() {
                break;
            }
            elm = left;
        }
        child = unsafe { (*elm).name_entry.rbe_right };
        parent = unsafe { (*elm).name_entry.rbe_parent };
        color = unsafe { (*elm).name_entry.rbe_color };
        if !child.is_null() {
            (unsafe { (*child).name_entry.rbe_parent = parent });
        }
        if !parent.is_null() {
            if (unsafe { (*parent).name_entry.rbe_left }) == elm {
                (unsafe { (*parent).name_entry.rbe_left = child });
            } else {
                (unsafe { (*parent).name_entry.rbe_right = child });
            }
        } else {
            (unsafe { (*head).rbh_root = child });
        }
        if (unsafe { (*elm).name_entry.rbe_parent }) == old {
            parent = elm;
        }
        (unsafe { (*elm).name_entry = (*old).name_entry });
        if !(unsafe { (*old).name_entry.rbe_parent }).is_null() {
            if (unsafe { (*(*old).name_entry.rbe_parent).name_entry.rbe_left }) == old {
                (unsafe { (*(*old).name_entry.rbe_parent).name_entry.rbe_left = elm });
            } else {
                (unsafe { (*(*old).name_entry.rbe_parent).name_entry.rbe_right = elm });
            }
        } else {
            (unsafe { (*head).rbh_root = elm });
        }
        (unsafe { (*(*old).name_entry.rbe_left).name_entry.rbe_parent = elm });
        if !(unsafe { (*old).name_entry.rbe_right }).is_null() {
            (unsafe { (*(*old).name_entry.rbe_right).name_entry.rbe_parent = elm });
        }
        if !parent.is_null() {
            left = parent;
            loop {
                left = unsafe { (*left).name_entry.rbe_parent };
                if left.is_null() {
                    break;
                }
            }
        }
        current_block = 12724331629892703003;
    }
    match current_block {
        7245201122033322888 => {
            parent = unsafe { (*elm).name_entry.rbe_parent };
            color = unsafe { (*elm).name_entry.rbe_color };
            if !child.is_null() {
                (unsafe { (*child).name_entry.rbe_parent = parent });
            }
            if !parent.is_null() {
                if (unsafe { (*parent).name_entry.rbe_left }) == elm {
                    (unsafe { (*parent).name_entry.rbe_left = child });
                } else {
                    (unsafe { (*parent).name_entry.rbe_right = child });
                }
            } else {
                (unsafe { (*head).rbh_root = child });
            }
        }
        _ => {}
    }
    if color == 0 {
        paste_name_tree_RB_REMOVE_COLOR(head, parent, child);
    }
    return old;
}
extern "C" fn paste_name_tree_RB_REMOVE_COLOR(
    mut head: *mut paste_name_tree,
    mut parent: *mut paste_buffer,
    mut elm: *mut paste_buffer,
) {
    let mut tmp: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    while (elm.is_null() || (unsafe { (*elm).name_entry.rbe_color }) == 0)
        && elm != (unsafe { (*head).rbh_root })
    {
        if (unsafe { (*parent).name_entry.rbe_left }) == elm {
            tmp = unsafe { (*parent).name_entry.rbe_right };
            if (unsafe { (*tmp).name_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).name_entry.rbe_color = 0 });
                (unsafe { (*parent).name_entry.rbe_color = 1 });
                tmp = unsafe { (*parent).name_entry.rbe_right };
                (unsafe { (*parent).name_entry.rbe_right = (*tmp).name_entry.rbe_left });
                if !(unsafe { (*parent).name_entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).name_entry.rbe_left).name_entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).name_entry.rbe_parent = (*parent).name_entry.rbe_parent });
                if !(unsafe { (*tmp).name_entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_left })
                    {
                        (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).name_entry.rbe_left = parent });
                (unsafe { (*parent).name_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).name_entry.rbe_parent }).is_null();
                tmp = unsafe { (*parent).name_entry.rbe_right };
            }
            if ((unsafe { (*tmp).name_entry.rbe_left }).is_null()
                || (unsafe { (*(*tmp).name_entry.rbe_left).name_entry.rbe_color }) == 0)
                && ((unsafe { (*tmp).name_entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).name_entry.rbe_right).name_entry.rbe_color }) == 0)
            {
                (unsafe { (*tmp).name_entry.rbe_color = 1 });
                elm = parent;
                parent = unsafe { (*elm).name_entry.rbe_parent };
            } else {
                if (unsafe { (*tmp).name_entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).name_entry.rbe_right).name_entry.rbe_color }) == 0
                {
                    let mut oleft: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
                    oleft = unsafe { (*tmp).name_entry.rbe_left };
                    if !oleft.is_null() {
                        (unsafe { (*oleft).name_entry.rbe_color = 0 });
                    }
                    (unsafe { (*tmp).name_entry.rbe_color = 1 });
                    oleft = unsafe { (*tmp).name_entry.rbe_left };
                    (unsafe { (*tmp).name_entry.rbe_left = (*oleft).name_entry.rbe_right });
                    if !(unsafe { (*tmp).name_entry.rbe_left }).is_null() {
                        (unsafe { (*(*oleft).name_entry.rbe_right).name_entry.rbe_parent = tmp });
                    }
                    (unsafe { (*oleft).name_entry.rbe_parent = (*tmp).name_entry.rbe_parent });
                    if !(unsafe { (*oleft).name_entry.rbe_parent }).is_null() {
                        if tmp == (unsafe { (*(*tmp).name_entry.rbe_parent).name_entry.rbe_left }) {
                            (unsafe {
                                (*(*tmp).name_entry.rbe_parent).name_entry.rbe_left = oleft
                            });
                        } else {
                            (unsafe {
                                (*(*tmp).name_entry.rbe_parent).name_entry.rbe_right = oleft
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = oleft });
                    }
                    (unsafe { (*oleft).name_entry.rbe_right = tmp });
                    (unsafe { (*tmp).name_entry.rbe_parent = oleft });
                    let _ = !(unsafe { (*oleft).name_entry.rbe_parent }).is_null();
                    tmp = unsafe { (*parent).name_entry.rbe_right };
                }
                (unsafe { (*tmp).name_entry.rbe_color = (*parent).name_entry.rbe_color });
                (unsafe { (*parent).name_entry.rbe_color = 0 });
                if !(unsafe { (*tmp).name_entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).name_entry.rbe_right).name_entry.rbe_color = 0 });
                }
                tmp = unsafe { (*parent).name_entry.rbe_right };
                (unsafe { (*parent).name_entry.rbe_right = (*tmp).name_entry.rbe_left });
                if !(unsafe { (*parent).name_entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).name_entry.rbe_left).name_entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).name_entry.rbe_parent = (*parent).name_entry.rbe_parent });
                if !(unsafe { (*tmp).name_entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_left })
                    {
                        (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).name_entry.rbe_left = parent });
                (unsafe { (*parent).name_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).name_entry.rbe_parent }).is_null();
                elm = unsafe { (*head).rbh_root };
                break;
            }
        } else {
            tmp = unsafe { (*parent).name_entry.rbe_left };
            if (unsafe { (*tmp).name_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).name_entry.rbe_color = 0 });
                (unsafe { (*parent).name_entry.rbe_color = 1 });
                tmp = unsafe { (*parent).name_entry.rbe_left };
                (unsafe { (*parent).name_entry.rbe_left = (*tmp).name_entry.rbe_right });
                if !(unsafe { (*parent).name_entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).name_entry.rbe_right).name_entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).name_entry.rbe_parent = (*parent).name_entry.rbe_parent });
                if !(unsafe { (*tmp).name_entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_left })
                    {
                        (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).name_entry.rbe_right = parent });
                (unsafe { (*parent).name_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).name_entry.rbe_parent }).is_null();
                tmp = unsafe { (*parent).name_entry.rbe_left };
            }
            if ((unsafe { (*tmp).name_entry.rbe_left }).is_null()
                || (unsafe { (*(*tmp).name_entry.rbe_left).name_entry.rbe_color }) == 0)
                && ((unsafe { (*tmp).name_entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).name_entry.rbe_right).name_entry.rbe_color }) == 0)
            {
                (unsafe { (*tmp).name_entry.rbe_color = 1 });
                elm = parent;
                parent = unsafe { (*elm).name_entry.rbe_parent };
            } else {
                if (unsafe { (*tmp).name_entry.rbe_left }).is_null()
                    || (unsafe { (*(*tmp).name_entry.rbe_left).name_entry.rbe_color }) == 0
                {
                    let mut oright: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
                    oright = unsafe { (*tmp).name_entry.rbe_right };
                    if !oright.is_null() {
                        (unsafe { (*oright).name_entry.rbe_color = 0 });
                    }
                    (unsafe { (*tmp).name_entry.rbe_color = 1 });
                    oright = unsafe { (*tmp).name_entry.rbe_right };
                    (unsafe { (*tmp).name_entry.rbe_right = (*oright).name_entry.rbe_left });
                    if !(unsafe { (*tmp).name_entry.rbe_right }).is_null() {
                        (unsafe { (*(*oright).name_entry.rbe_left).name_entry.rbe_parent = tmp });
                    }
                    (unsafe { (*oright).name_entry.rbe_parent = (*tmp).name_entry.rbe_parent });
                    if !(unsafe { (*oright).name_entry.rbe_parent }).is_null() {
                        if tmp == (unsafe { (*(*tmp).name_entry.rbe_parent).name_entry.rbe_left }) {
                            (unsafe {
                                (*(*tmp).name_entry.rbe_parent).name_entry.rbe_left = oright
                            });
                        } else {
                            (unsafe {
                                (*(*tmp).name_entry.rbe_parent).name_entry.rbe_right = oright
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = oright });
                    }
                    (unsafe { (*oright).name_entry.rbe_left = tmp });
                    (unsafe { (*tmp).name_entry.rbe_parent = oright });
                    let _ = !(unsafe { (*oright).name_entry.rbe_parent }).is_null();
                    tmp = unsafe { (*parent).name_entry.rbe_left };
                }
                (unsafe { (*tmp).name_entry.rbe_color = (*parent).name_entry.rbe_color });
                (unsafe { (*parent).name_entry.rbe_color = 0 });
                if !(unsafe { (*tmp).name_entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).name_entry.rbe_left).name_entry.rbe_color = 0 });
                }
                tmp = unsafe { (*parent).name_entry.rbe_left };
                (unsafe { (*parent).name_entry.rbe_left = (*tmp).name_entry.rbe_right });
                if !(unsafe { (*parent).name_entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).name_entry.rbe_right).name_entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).name_entry.rbe_parent = (*parent).name_entry.rbe_parent });
                if !(unsafe { (*tmp).name_entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_left })
                    {
                        (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).name_entry.rbe_parent).name_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).name_entry.rbe_right = parent });
                (unsafe { (*parent).name_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).name_entry.rbe_parent }).is_null();
                elm = unsafe { (*head).rbh_root };
                break;
            }
        }
    }
    if !elm.is_null() {
        (unsafe { (*elm).name_entry.rbe_color = 0 });
    }
}
extern "C" fn paste_time_tree_RB_MINMAX(
    mut head: *mut paste_time_tree,
    mut val: i32,
) -> *mut paste_buffer {
    let mut tmp: *mut paste_buffer = unsafe { (*head).rbh_root };
    let mut parent: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    while !tmp.is_null() {
        parent = tmp;
        if val < 0 {
            tmp = unsafe { (*tmp).time_entry.rbe_left };
        } else {
            tmp = unsafe { (*tmp).time_entry.rbe_right };
        }
    }
    return parent;
}
extern "C" fn paste_time_tree_RB_NEXT(mut elm: *mut paste_buffer) -> *mut paste_buffer {
    if !(unsafe { (*elm).time_entry.rbe_right }).is_null() {
        elm = unsafe { (*elm).time_entry.rbe_right };
        while !(unsafe { (*elm).time_entry.rbe_left }).is_null() {
            elm = unsafe { (*elm).time_entry.rbe_left };
        }
    } else if !(unsafe { (*elm).time_entry.rbe_parent }).is_null()
        && elm == (unsafe { (*(*elm).time_entry.rbe_parent).time_entry.rbe_left })
    {
        elm = unsafe { (*elm).time_entry.rbe_parent };
    } else {
        while !(unsafe { (*elm).time_entry.rbe_parent }).is_null()
            && elm == (unsafe { (*(*elm).time_entry.rbe_parent).time_entry.rbe_right })
        {
            elm = unsafe { (*elm).time_entry.rbe_parent };
        }
        elm = unsafe { (*elm).time_entry.rbe_parent };
    }
    return elm;
}
extern "C" fn paste_time_tree_RB_INSERT(
    mut head: *mut paste_time_tree,
    mut elm: *mut paste_buffer,
) -> *mut paste_buffer {
    let mut tmp: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut parent: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut comp: i32 = 0;
    tmp = unsafe { (*head).rbh_root };
    while !tmp.is_null() {
        parent = tmp;
        comp = paste_cmp_times(elm, parent);
        if comp < 0 {
            tmp = unsafe { (*tmp).time_entry.rbe_left };
        } else if comp > 0 {
            tmp = unsafe { (*tmp).time_entry.rbe_right };
        } else {
            return tmp;
        }
    }
    (unsafe { (*elm).time_entry.rbe_parent = parent });
    (unsafe { (*elm).time_entry.rbe_right = std::ptr::null_mut::<paste_buffer>() });
    (unsafe { (*elm).time_entry.rbe_left = (*elm).time_entry.rbe_right });
    (unsafe { (*elm).time_entry.rbe_color = 1 });
    if !parent.is_null() {
        if comp < 0 {
            (unsafe { (*parent).time_entry.rbe_left = elm });
        } else {
            (unsafe { (*parent).time_entry.rbe_right = elm });
        }
    } else {
        (unsafe { (*head).rbh_root = elm });
    }
    paste_time_tree_RB_INSERT_COLOR(head, elm);
    return std::ptr::null_mut::<paste_buffer>();
}
extern "C" fn paste_time_tree_RB_REMOVE_COLOR(
    mut head: *mut paste_time_tree,
    mut parent: *mut paste_buffer,
    mut elm: *mut paste_buffer,
) {
    let mut tmp: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    while (elm.is_null() || (unsafe { (*elm).time_entry.rbe_color }) == 0)
        && elm != (unsafe { (*head).rbh_root })
    {
        if (unsafe { (*parent).time_entry.rbe_left }) == elm {
            tmp = unsafe { (*parent).time_entry.rbe_right };
            if (unsafe { (*tmp).time_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).time_entry.rbe_color = 0 });
                (unsafe { (*parent).time_entry.rbe_color = 1 });
                tmp = unsafe { (*parent).time_entry.rbe_right };
                (unsafe { (*parent).time_entry.rbe_right = (*tmp).time_entry.rbe_left });
                if !(unsafe { (*parent).time_entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).time_entry.rbe_left).time_entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).time_entry.rbe_parent = (*parent).time_entry.rbe_parent });
                if !(unsafe { (*tmp).time_entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_left })
                    {
                        (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).time_entry.rbe_left = parent });
                (unsafe { (*parent).time_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).time_entry.rbe_parent }).is_null();
                tmp = unsafe { (*parent).time_entry.rbe_right };
            }
            if ((unsafe { (*tmp).time_entry.rbe_left }).is_null()
                || (unsafe { (*(*tmp).time_entry.rbe_left).time_entry.rbe_color }) == 0)
                && ((unsafe { (*tmp).time_entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).time_entry.rbe_right).time_entry.rbe_color }) == 0)
            {
                (unsafe { (*tmp).time_entry.rbe_color = 1 });
                elm = parent;
                parent = unsafe { (*elm).time_entry.rbe_parent };
            } else {
                if (unsafe { (*tmp).time_entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).time_entry.rbe_right).time_entry.rbe_color }) == 0
                {
                    let mut oleft: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
                    oleft = unsafe { (*tmp).time_entry.rbe_left };
                    if !oleft.is_null() {
                        (unsafe { (*oleft).time_entry.rbe_color = 0 });
                    }
                    (unsafe { (*tmp).time_entry.rbe_color = 1 });
                    oleft = unsafe { (*tmp).time_entry.rbe_left };
                    (unsafe { (*tmp).time_entry.rbe_left = (*oleft).time_entry.rbe_right });
                    if !(unsafe { (*tmp).time_entry.rbe_left }).is_null() {
                        (unsafe { (*(*oleft).time_entry.rbe_right).time_entry.rbe_parent = tmp });
                    }
                    (unsafe { (*oleft).time_entry.rbe_parent = (*tmp).time_entry.rbe_parent });
                    if !(unsafe { (*oleft).time_entry.rbe_parent }).is_null() {
                        if tmp == (unsafe { (*(*tmp).time_entry.rbe_parent).time_entry.rbe_left }) {
                            (unsafe {
                                (*(*tmp).time_entry.rbe_parent).time_entry.rbe_left = oleft
                            });
                        } else {
                            (unsafe {
                                (*(*tmp).time_entry.rbe_parent).time_entry.rbe_right = oleft
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = oleft });
                    }
                    (unsafe { (*oleft).time_entry.rbe_right = tmp });
                    (unsafe { (*tmp).time_entry.rbe_parent = oleft });
                    let _ = !(unsafe { (*oleft).time_entry.rbe_parent }).is_null();
                    tmp = unsafe { (*parent).time_entry.rbe_right };
                }
                (unsafe { (*tmp).time_entry.rbe_color = (*parent).time_entry.rbe_color });
                (unsafe { (*parent).time_entry.rbe_color = 0 });
                if !(unsafe { (*tmp).time_entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).time_entry.rbe_right).time_entry.rbe_color = 0 });
                }
                tmp = unsafe { (*parent).time_entry.rbe_right };
                (unsafe { (*parent).time_entry.rbe_right = (*tmp).time_entry.rbe_left });
                if !(unsafe { (*parent).time_entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).time_entry.rbe_left).time_entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).time_entry.rbe_parent = (*parent).time_entry.rbe_parent });
                if !(unsafe { (*tmp).time_entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_left })
                    {
                        (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).time_entry.rbe_left = parent });
                (unsafe { (*parent).time_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).time_entry.rbe_parent }).is_null();
                elm = unsafe { (*head).rbh_root };
                break;
            }
        } else {
            tmp = unsafe { (*parent).time_entry.rbe_left };
            if (unsafe { (*tmp).time_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).time_entry.rbe_color = 0 });
                (unsafe { (*parent).time_entry.rbe_color = 1 });
                tmp = unsafe { (*parent).time_entry.rbe_left };
                (unsafe { (*parent).time_entry.rbe_left = (*tmp).time_entry.rbe_right });
                if !(unsafe { (*parent).time_entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).time_entry.rbe_right).time_entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).time_entry.rbe_parent = (*parent).time_entry.rbe_parent });
                if !(unsafe { (*tmp).time_entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_left })
                    {
                        (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).time_entry.rbe_right = parent });
                (unsafe { (*parent).time_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).time_entry.rbe_parent }).is_null();
                tmp = unsafe { (*parent).time_entry.rbe_left };
            }
            if ((unsafe { (*tmp).time_entry.rbe_left }).is_null()
                || (unsafe { (*(*tmp).time_entry.rbe_left).time_entry.rbe_color }) == 0)
                && ((unsafe { (*tmp).time_entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).time_entry.rbe_right).time_entry.rbe_color }) == 0)
            {
                (unsafe { (*tmp).time_entry.rbe_color = 1 });
                elm = parent;
                parent = unsafe { (*elm).time_entry.rbe_parent };
            } else {
                if (unsafe { (*tmp).time_entry.rbe_left }).is_null()
                    || (unsafe { (*(*tmp).time_entry.rbe_left).time_entry.rbe_color }) == 0
                {
                    let mut oright: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
                    oright = unsafe { (*tmp).time_entry.rbe_right };
                    if !oright.is_null() {
                        (unsafe { (*oright).time_entry.rbe_color = 0 });
                    }
                    (unsafe { (*tmp).time_entry.rbe_color = 1 });
                    oright = unsafe { (*tmp).time_entry.rbe_right };
                    (unsafe { (*tmp).time_entry.rbe_right = (*oright).time_entry.rbe_left });
                    if !(unsafe { (*tmp).time_entry.rbe_right }).is_null() {
                        (unsafe { (*(*oright).time_entry.rbe_left).time_entry.rbe_parent = tmp });
                    }
                    (unsafe { (*oright).time_entry.rbe_parent = (*tmp).time_entry.rbe_parent });
                    if !(unsafe { (*oright).time_entry.rbe_parent }).is_null() {
                        if tmp == (unsafe { (*(*tmp).time_entry.rbe_parent).time_entry.rbe_left }) {
                            (unsafe {
                                (*(*tmp).time_entry.rbe_parent).time_entry.rbe_left = oright
                            });
                        } else {
                            (unsafe {
                                (*(*tmp).time_entry.rbe_parent).time_entry.rbe_right = oright
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = oright });
                    }
                    (unsafe { (*oright).time_entry.rbe_left = tmp });
                    (unsafe { (*tmp).time_entry.rbe_parent = oright });
                    let _ = !(unsafe { (*oright).time_entry.rbe_parent }).is_null();
                    tmp = unsafe { (*parent).time_entry.rbe_left };
                }
                (unsafe { (*tmp).time_entry.rbe_color = (*parent).time_entry.rbe_color });
                (unsafe { (*parent).time_entry.rbe_color = 0 });
                if !(unsafe { (*tmp).time_entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).time_entry.rbe_left).time_entry.rbe_color = 0 });
                }
                tmp = unsafe { (*parent).time_entry.rbe_left };
                (unsafe { (*parent).time_entry.rbe_left = (*tmp).time_entry.rbe_right });
                if !(unsafe { (*parent).time_entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).time_entry.rbe_right).time_entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).time_entry.rbe_parent = (*parent).time_entry.rbe_parent });
                if !(unsafe { (*tmp).time_entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_left })
                    {
                        (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).time_entry.rbe_right = parent });
                (unsafe { (*parent).time_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).time_entry.rbe_parent }).is_null();
                elm = unsafe { (*head).rbh_root };
                break;
            }
        }
    }
    if !elm.is_null() {
        (unsafe { (*elm).time_entry.rbe_color = 0 });
    }
}
extern "C" fn paste_time_tree_RB_REMOVE(
    mut head: *mut paste_time_tree,
    mut elm: *mut paste_buffer,
) -> *mut paste_buffer {
    let mut current_block: u64;
    let mut child: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut parent: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut old: *mut paste_buffer = elm;
    let mut color: i32 = 0;
    if (unsafe { (*elm).time_entry.rbe_left }).is_null() {
        child = unsafe { (*elm).time_entry.rbe_right };
        current_block = 7245201122033322888;
    } else if (unsafe { (*elm).time_entry.rbe_right }).is_null() {
        child = unsafe { (*elm).time_entry.rbe_left };
        current_block = 7245201122033322888;
    } else {
        let mut left: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
        elm = unsafe { (*elm).time_entry.rbe_right };
        loop {
            left = unsafe { (*elm).time_entry.rbe_left };
            if left.is_null() {
                break;
            }
            elm = left;
        }
        child = unsafe { (*elm).time_entry.rbe_right };
        parent = unsafe { (*elm).time_entry.rbe_parent };
        color = unsafe { (*elm).time_entry.rbe_color };
        if !child.is_null() {
            (unsafe { (*child).time_entry.rbe_parent = parent });
        }
        if !parent.is_null() {
            if (unsafe { (*parent).time_entry.rbe_left }) == elm {
                (unsafe { (*parent).time_entry.rbe_left = child });
            } else {
                (unsafe { (*parent).time_entry.rbe_right = child });
            }
        } else {
            (unsafe { (*head).rbh_root = child });
        }
        if (unsafe { (*elm).time_entry.rbe_parent }) == old {
            parent = elm;
        }
        (unsafe { (*elm).time_entry = (*old).time_entry });
        if !(unsafe { (*old).time_entry.rbe_parent }).is_null() {
            if (unsafe { (*(*old).time_entry.rbe_parent).time_entry.rbe_left }) == old {
                (unsafe { (*(*old).time_entry.rbe_parent).time_entry.rbe_left = elm });
            } else {
                (unsafe { (*(*old).time_entry.rbe_parent).time_entry.rbe_right = elm });
            }
        } else {
            (unsafe { (*head).rbh_root = elm });
        }
        (unsafe { (*(*old).time_entry.rbe_left).time_entry.rbe_parent = elm });
        if !(unsafe { (*old).time_entry.rbe_right }).is_null() {
            (unsafe { (*(*old).time_entry.rbe_right).time_entry.rbe_parent = elm });
        }
        if !parent.is_null() {
            left = parent;
            loop {
                left = unsafe { (*left).time_entry.rbe_parent };
                if left.is_null() {
                    break;
                }
            }
        }
        current_block = 5285952531898605950;
    }
    match current_block {
        7245201122033322888 => {
            parent = unsafe { (*elm).time_entry.rbe_parent };
            color = unsafe { (*elm).time_entry.rbe_color };
            if !child.is_null() {
                (unsafe { (*child).time_entry.rbe_parent = parent });
            }
            if !parent.is_null() {
                if (unsafe { (*parent).time_entry.rbe_left }) == elm {
                    (unsafe { (*parent).time_entry.rbe_left = child });
                } else {
                    (unsafe { (*parent).time_entry.rbe_right = child });
                }
            } else {
                (unsafe { (*head).rbh_root = child });
            }
        }
        _ => {}
    }
    if color == 0 {
        paste_time_tree_RB_REMOVE_COLOR(head, parent, child);
    }
    return old;
}
extern "C" fn paste_time_tree_RB_INSERT_COLOR(
    mut head: *mut paste_time_tree,
    mut elm: *mut paste_buffer,
) {
    let mut parent: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut gparent: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut tmp: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    loop {
        parent = unsafe { (*elm).time_entry.rbe_parent };
        if parent.is_null() || (unsafe { (*parent).time_entry.rbe_color }) != 1 {
            break;
        }
        gparent = unsafe { (*parent).time_entry.rbe_parent };
        if parent == (unsafe { (*gparent).time_entry.rbe_left }) {
            tmp = unsafe { (*gparent).time_entry.rbe_right };
            if !tmp.is_null() && (unsafe { (*tmp).time_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).time_entry.rbe_color = 0 });
                (unsafe { (*parent).time_entry.rbe_color = 0 });
                (unsafe { (*gparent).time_entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).time_entry.rbe_right }) == elm {
                    tmp = unsafe { (*parent).time_entry.rbe_right };
                    (unsafe { (*parent).time_entry.rbe_right = (*tmp).time_entry.rbe_left });
                    if !(unsafe { (*parent).time_entry.rbe_right }).is_null() {
                        (unsafe { (*(*tmp).time_entry.rbe_left).time_entry.rbe_parent = parent });
                    }
                    (unsafe { (*tmp).time_entry.rbe_parent = (*parent).time_entry.rbe_parent });
                    if !(unsafe { (*tmp).time_entry.rbe_parent }).is_null() {
                        if parent
                            == (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_left })
                        {
                            (unsafe {
                                (*(*parent).time_entry.rbe_parent).time_entry.rbe_left = tmp
                            });
                        } else {
                            (unsafe {
                                (*(*parent).time_entry.rbe_parent).time_entry.rbe_right = tmp
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).time_entry.rbe_left = parent });
                    (unsafe { (*parent).time_entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).time_entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).time_entry.rbe_color = 0 });
                (unsafe { (*gparent).time_entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).time_entry.rbe_left };
                (unsafe { (*gparent).time_entry.rbe_left = (*tmp).time_entry.rbe_right });
                if !(unsafe { (*gparent).time_entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).time_entry.rbe_right).time_entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).time_entry.rbe_parent = (*gparent).time_entry.rbe_parent });
                if !(unsafe { (*tmp).time_entry.rbe_parent }).is_null() {
                    if gparent
                        == (unsafe { (*(*gparent).time_entry.rbe_parent).time_entry.rbe_left })
                    {
                        (unsafe { (*(*gparent).time_entry.rbe_parent).time_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*gparent).time_entry.rbe_parent).time_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).time_entry.rbe_right = gparent });
                (unsafe { (*gparent).time_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).time_entry.rbe_parent }).is_null();
            }
        } else {
            tmp = unsafe { (*gparent).time_entry.rbe_left };
            if !tmp.is_null() && (unsafe { (*tmp).time_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).time_entry.rbe_color = 0 });
                (unsafe { (*parent).time_entry.rbe_color = 0 });
                (unsafe { (*gparent).time_entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).time_entry.rbe_left }) == elm {
                    tmp = unsafe { (*parent).time_entry.rbe_left };
                    (unsafe { (*parent).time_entry.rbe_left = (*tmp).time_entry.rbe_right });
                    if !(unsafe { (*parent).time_entry.rbe_left }).is_null() {
                        (unsafe { (*(*tmp).time_entry.rbe_right).time_entry.rbe_parent = parent });
                    }
                    (unsafe { (*tmp).time_entry.rbe_parent = (*parent).time_entry.rbe_parent });
                    if !(unsafe { (*tmp).time_entry.rbe_parent }).is_null() {
                        if parent
                            == (unsafe { (*(*parent).time_entry.rbe_parent).time_entry.rbe_left })
                        {
                            (unsafe {
                                (*(*parent).time_entry.rbe_parent).time_entry.rbe_left = tmp
                            });
                        } else {
                            (unsafe {
                                (*(*parent).time_entry.rbe_parent).time_entry.rbe_right = tmp
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).time_entry.rbe_right = parent });
                    (unsafe { (*parent).time_entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).time_entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).time_entry.rbe_color = 0 });
                (unsafe { (*gparent).time_entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).time_entry.rbe_right };
                (unsafe { (*gparent).time_entry.rbe_right = (*tmp).time_entry.rbe_left });
                if !(unsafe { (*gparent).time_entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).time_entry.rbe_left).time_entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).time_entry.rbe_parent = (*gparent).time_entry.rbe_parent });
                if !(unsafe { (*tmp).time_entry.rbe_parent }).is_null() {
                    if gparent
                        == (unsafe { (*(*gparent).time_entry.rbe_parent).time_entry.rbe_left })
                    {
                        (unsafe { (*(*gparent).time_entry.rbe_parent).time_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*gparent).time_entry.rbe_parent).time_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).time_entry.rbe_left = gparent });
                (unsafe { (*gparent).time_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).time_entry.rbe_parent }).is_null();
            }
        }
    }
    (unsafe { (*(*head).rbh_root).time_entry.rbe_color = 0 });
}
extern "C" fn paste_time_tree_RB_PREV(mut elm: *mut paste_buffer) -> *mut paste_buffer {
    if !(unsafe { (*elm).time_entry.rbe_left }).is_null() {
        elm = unsafe { (*elm).time_entry.rbe_left };
        while !(unsafe { (*elm).time_entry.rbe_right }).is_null() {
            elm = unsafe { (*elm).time_entry.rbe_right };
        }
    } else if !(unsafe { (*elm).time_entry.rbe_parent }).is_null()
        && elm == (unsafe { (*(*elm).time_entry.rbe_parent).time_entry.rbe_right })
    {
        elm = unsafe { (*elm).time_entry.rbe_parent };
    } else {
        while !(unsafe { (*elm).time_entry.rbe_parent }).is_null()
            && elm == (unsafe { (*(*elm).time_entry.rbe_parent).time_entry.rbe_left })
        {
            elm = unsafe { (*elm).time_entry.rbe_parent };
        }
        elm = unsafe { (*elm).time_entry.rbe_parent };
    }
    return elm;
}
extern "C" fn paste_cmp_names(mut a: *const paste_buffer, mut b: *const paste_buffer) -> i32 {
    return unsafe { strcmp((*a).name, (*b).name) };
}
extern "C" fn paste_cmp_times(mut a: *const paste_buffer, mut b: *const paste_buffer) -> i32 {
    if (unsafe { (*a).order }) > (unsafe { (*b).order }) {
        return -(1 as i32);
    }
    if (unsafe { (*a).order }) < (unsafe { (*b).order }) {
        return 1;
    }
    return 0;
}
#[no_mangle]
pub extern "C" fn paste_buffer_name(mut pb: *mut paste_buffer) -> *const i8 {
    return unsafe { (*pb).name };
}
#[no_mangle]
pub extern "C" fn paste_buffer_order(mut pb: *mut paste_buffer) -> u_int {
    return unsafe { (*pb).order };
}
#[no_mangle]
pub extern "C" fn paste_buffer_created(mut pb: *mut paste_buffer) -> time_t {
    return unsafe { (*pb).created };
}
#[no_mangle]
pub extern "C" fn paste_buffer_data(mut pb: *mut paste_buffer, mut size: *mut size_t) -> *const i8 {
    if !size.is_null() {
        (unsafe { *size = (*pb).size });
    }
    return unsafe { (*pb).data };
}
#[no_mangle]
pub extern "C" fn paste_walk(mut pb: *mut paste_buffer) -> *mut paste_buffer {
    if pb.is_null() {
        return paste_time_tree_RB_MINMAX(unsafe { &mut paste_by_time }, -(1 as i32));
    }
    return paste_time_tree_RB_NEXT(pb);
}
#[no_mangle]
pub extern "C" fn paste_is_empty() -> i32 {
    return ((unsafe { paste_by_time.rbh_root })
        == std::ptr::null_mut::<()>() as *mut paste_buffer) as i32;
}
#[no_mangle]
pub extern "C" fn paste_get_top(mut name: *mut *const i8) -> *mut paste_buffer {
    let mut pb: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    pb = paste_time_tree_RB_MINMAX(unsafe { &mut paste_by_time }, -(1 as i32));
    while !pb.is_null() && (unsafe { (*pb).automatic }) == 0 {
        pb = paste_time_tree_RB_NEXT(pb);
    }
    if pb.is_null() {
        return std::ptr::null_mut::<paste_buffer>();
    }
    if !name.is_null() {
        (unsafe { *name = (*pb).name });
    }
    return pb;
}
#[no_mangle]
pub extern "C" fn paste_get_name(mut name: *const i8) -> *mut paste_buffer {
    let mut pbfind: paste_buffer = paste_buffer {
        data: std::ptr::null_mut::<i8>(),
        size: 0,
        name: std::ptr::null_mut::<i8>(),
        created: 0,
        automatic: 0,
        order: 0,
        name_entry: C2RustUnnamed_0 {
            rbe_left: std::ptr::null_mut::<paste_buffer>(),
            rbe_right: std::ptr::null_mut::<paste_buffer>(),
            rbe_parent: std::ptr::null_mut::<paste_buffer>(),
            rbe_color: 0,
        },
        time_entry: C2RustUnnamed {
            rbe_left: std::ptr::null_mut::<paste_buffer>(),
            rbe_right: std::ptr::null_mut::<paste_buffer>(),
            rbe_parent: std::ptr::null_mut::<paste_buffer>(),
            rbe_color: 0,
        },
    };
    if name.is_null() || (unsafe { *name }) as i32 == '\0' as i32 {
        return std::ptr::null_mut::<paste_buffer>();
    }
    pbfind.name = name as *mut i8;
    return paste_name_tree_RB_FIND(unsafe { &mut paste_by_name }, &mut pbfind);
}
#[no_mangle]
pub extern "C" fn paste_free(mut pb: *mut paste_buffer) {
    (unsafe { notify_paste_buffer((*pb).name, 1) });
    paste_name_tree_RB_REMOVE(unsafe { &mut paste_by_name }, pb);
    paste_time_tree_RB_REMOVE(unsafe { &mut paste_by_time }, pb);
    if (unsafe { (*pb).automatic }) != 0 {
        (unsafe { paste_num_automatic = paste_num_automatic.wrapping_sub(1) });
    }
    (unsafe { free((*pb).data as *mut ()) });
    (unsafe { free((*pb).name as *mut ()) });
    (unsafe { free(pb as *mut ()) });
}
#[no_mangle]
pub extern "C" fn paste_add(mut prefix: *const i8, mut data: *mut i8, mut size: size_t) {
    let mut pb: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut pb1: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut limit: u_int = 0;
    if prefix.is_null() {
        prefix = b"buffer\0" as *const u8 as *const i8;
    }
    if size == 0 as u64 {
        (unsafe { free(data as *mut ()) });
        return;
    }
    limit = (unsafe {
        options_get_number(global_options, b"buffer-limit\0" as *const u8 as *const i8)
    }) as u_int;
    pb = paste_time_tree_RB_MINMAX(unsafe { &mut paste_by_time }, 1);
    while !pb.is_null() && {
        pb1 = paste_time_tree_RB_PREV(pb); 1 != 0
    } {
        if (unsafe { paste_num_automatic }) < limit {
            break;
        }
        if (unsafe { (*pb).automatic }) != 0 {
            paste_free(pb);
        }
        pb = pb1;
    }
    pb = (unsafe { xmalloc(::core::mem::size_of::<paste_buffer>() as u64) }) as *mut paste_buffer;
    (unsafe { (*pb).name = std::ptr::null_mut::<i8>() });
    loop {
        (unsafe { free((*pb).name as *mut ()) });
        (unsafe {
            xasprintf(
                &mut (*pb).name as *mut *mut i8,
                b"%s%u\0" as *const u8 as *const i8,
                prefix,
                paste_next_index,
            )
        });
        (unsafe { paste_next_index = paste_next_index.wrapping_add(1) });
        if (paste_get_name(unsafe { (*pb).name })).is_null() {
            break;
        }
    }
    (unsafe { (*pb).data = data });
    (unsafe { (*pb).size = size });
    (unsafe { (*pb).automatic = 1 });
    (unsafe { paste_num_automatic = paste_num_automatic.wrapping_add(1) });
    (unsafe { (*pb).created = time(std::ptr::null_mut::<time_t>()) });
    let fresh0 = unsafe { paste_next_order };
    (unsafe { paste_next_order = paste_next_order.wrapping_add(1) });
    (unsafe { (*pb).order = fresh0 });
    paste_name_tree_RB_INSERT(unsafe { &mut paste_by_name }, pb);
    paste_time_tree_RB_INSERT(unsafe { &mut paste_by_time }, pb);
    (unsafe { notify_paste_buffer((*pb).name, 0) });
}
#[no_mangle]
pub extern "C" fn paste_rename(
    mut oldname: *const i8,
    mut newname: *const i8,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut pb: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut pb_new: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    if !cause.is_null() {
        (unsafe { *cause = std::ptr::null_mut::<i8>() });
    }
    if oldname.is_null() || (unsafe { *oldname }) as i32 == '\0' as i32 {
        if !cause.is_null() {
            (unsafe { *cause = xstrdup(b"no buffer\0" as *const u8 as *const i8) });
        }
        return -(1 as i32);
    }
    if newname.is_null() || (unsafe { *newname }) as i32 == '\0' as i32 {
        if !cause.is_null() {
            (unsafe { *cause = xstrdup(b"new name is empty\0" as *const u8 as *const i8) });
        }
        return -(1 as i32);
    }
    pb = paste_get_name(oldname);
    if pb.is_null() {
        if !cause.is_null() {
            (unsafe { xasprintf(cause, b"no buffer %s\0" as *const u8 as *const i8, oldname) });
        }
        return -(1 as i32);
    }
    pb_new = paste_get_name(newname);
    if pb_new == pb {
        return 0;
    }
    if !pb_new.is_null() {
        paste_free(pb_new);
    }
    paste_name_tree_RB_REMOVE(unsafe { &mut paste_by_name }, pb);
    (unsafe { free((*pb).name as *mut ()) });
    (unsafe { (*pb).name = xstrdup(newname) });
    if (unsafe { (*pb).automatic }) != 0 {
        (unsafe { paste_num_automatic = paste_num_automatic.wrapping_sub(1) });
    }
    (unsafe { (*pb).automatic = 0 });
    paste_name_tree_RB_INSERT(unsafe { &mut paste_by_name }, pb);
    (unsafe { notify_paste_buffer(oldname, 1) });
    (unsafe { notify_paste_buffer(newname, 0) });
    return 0;
}
#[no_mangle]
pub extern "C" fn paste_set(
    mut data: *mut i8,
    mut size: size_t,
    mut name: *const i8,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut pb: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    let mut old: *mut paste_buffer = std::ptr::null_mut::<paste_buffer>();
    if !cause.is_null() {
        (unsafe { *cause = std::ptr::null_mut::<i8>() });
    }
    if size == 0 as u64 {
        (unsafe { free(data as *mut ()) });
        return 0;
    }
    if name.is_null() {
        paste_add(std::ptr::null::<i8>(), data, size);
        return 0;
    }
    if (unsafe { *name }) as i32 == '\0' as i32 {
        if !cause.is_null() {
            (unsafe { *cause = xstrdup(b"empty buffer name\0" as *const u8 as *const i8) });
        }
        return -(1 as i32);
    }
    pb = (unsafe { xmalloc(::core::mem::size_of::<paste_buffer>() as u64) }) as *mut paste_buffer;
    (unsafe { (*pb).name = xstrdup(name) });
    (unsafe { (*pb).data = data });
    (unsafe { (*pb).size = size });
    (unsafe { (*pb).automatic = 0 });
    let fresh1 = unsafe { paste_next_order };
    (unsafe { paste_next_order = paste_next_order.wrapping_add(1) });
    (unsafe { (*pb).order = fresh1 });
    (unsafe { (*pb).created = time(std::ptr::null_mut::<time_t>()) });
    old = paste_get_name(name);
    if !old.is_null() {
        paste_free(old);
    }
    paste_name_tree_RB_INSERT(unsafe { &mut paste_by_name }, pb);
    paste_time_tree_RB_INSERT(unsafe { &mut paste_by_time }, pb);
    (unsafe { notify_paste_buffer(name, 0) });
    return 0;
}
#[no_mangle]
pub extern "C" fn paste_replace(mut pb: *mut paste_buffer, mut data: *mut i8, mut size: size_t) {
    (unsafe { free((*pb).data as *mut ()) });
    (unsafe { (*pb).data = data });
    (unsafe { (*pb).size = size });
    (unsafe { notify_paste_buffer((*pb).name, 0) });
}
#[no_mangle]
pub extern "C" fn paste_make_sample(mut pb: *mut paste_buffer) -> *mut i8 {
    let mut buf: *mut i8 = std::ptr::null_mut::<i8>();
    let mut len: size_t = 0;
    let mut used: size_t = 0;
    let flags: i32 = 0x1 as i32 | 0x2 as i32 | 0x8 as i32 | 0x10 as i32;
    let width: size_t = 200 as size_t;
    len = unsafe { (*pb).size };
    if len > width {
        len = width;
    }
    buf = (unsafe {
        xreallocarray(
            std::ptr::null_mut::<()>(),
            len,
            (4 as i32 + 4) as size_t,
        )
    }) as *mut i8;
    used = (unsafe { utf8_strvis(buf, (*pb).data, len, flags) }) as size_t;
    if (unsafe { (*pb).size }) > width || used > width {
        (unsafe {
            strlcpy(
                buf.offset(width as isize),
                b"...\0" as *const u8 as *const i8, 4 as size_t,
            )
        });
    }
    return buf;
}
